package com.ruoyi.storage.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.domain.WarehouseLocation;
import com.ruoyi.storage.service.IWarehouseLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库位管理Controller
 * 
 * @author 庞一恺
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/storage/warehouseLocation")
public class WarehouseLocationController extends BaseController
{
    @Autowired
    private IWarehouseLocationService warehouseLocationService;

    /**
     * 查询库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseLocation warehouseLocation)
    {
        startPage();
        List<WarehouseLocation> list = warehouseLocationService.selectWarehouseLocationList(warehouseLocation, Math.toIntExact(SecurityUtils.getUserId()));
        return getDataTable(list);
    }

    /**
     * 导出库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:export')")
    @Log(title = "库位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseLocation warehouseLocation)
    {
        List<WarehouseLocation> list = warehouseLocationService.selectWarehouseLocationList(warehouseLocation, Math.toIntExact(SecurityUtils.getUserId()));
        ExcelUtil<WarehouseLocation> util = new ExcelUtil<WarehouseLocation>(WarehouseLocation.class);
        util.exportExcel(response, list, "库位管理数据");
    }

    /**
     * 获取库位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Integer locationId)
    {
        return success(warehouseLocationService.selectWarehouseLocationByLocationId(locationId));
    }

    /**
     * 新增库位管理
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:add')")
    @Log(title = "库位管理", businessType = BusinessType.INSERT)
    @PostMapping("/{areaId}/{quantity}")
    public AjaxResult add(@PathVariable Integer areaId, @PathVariable Integer quantity) {

        return toAjax(warehouseLocationService.insertWarehouseLocation(areaId, quantity));
    }

    /**
     * 修改库位管理
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:edit')")
    @Log(title = "库位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseLocation warehouseLocation)
    {
        return toAjax(warehouseLocationService.updateWarehouseLocation(warehouseLocation));
    }

    /**
     * 删除库位管理
     */
    @PreAuthorize("@ss.hasPermi('storage:warehouseLocation:remove')")
    @Log(title = "库位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Integer[] locationIds)
    {
        return toAjax(warehouseLocationService.deleteWarehouseLocationByLocationIds(locationIds));
    }
}
